$(function () {
    //表单验证
    $.formValidator.initConfig({
        formID: "dataForm", mode: 'AutoTip', onError: function (msg) {
            alert(msg)
        }
    });
    $("#name").formValidator({onShow: "", onFocus: "请输入使用者姓名"}).inputValidator({
        min: 6,
        max: 60,
        onError: "使用者姓名不合格"
    });
    $("#mobile").formValidator({onShow: "", onFocus: "请输入11位登录手机"})
        .functionValidator({fun: isMobile});

    $("#cert_id").formValidator({onShow: "", onFocus: "输入15或18位的身份证", onCorrect: "身份证有效"})
        .functionValidator({fun: isCardID});

    $("#invite_code").formValidator({onShow: "", onFocus: "请获取邀请码"}).inputValidator({
        min: 1,
        onError: "邀请码不能为空"
    });
    $("#password").formValidator({onShow: "", onFocus: "请输入登录密码"}).inputValidator({
        min: 6,
        max: 18,
        onError: "登录密码格式错误"
    });
    $("#headimg").formValidator({onShow: "", onFocus: "请选择合伙人图像"}).inputValidator({
        min: 1,
        onError: "合伙人图像不能为空"
    });
    $("#province1").formValidator({onShow: "", onFocus: "请选择所在省份"})
        .functionValidator({fun: selProvice});
    $("#city1").formValidator({onShow: "", onFocus: "请选择所在城市"})
        .functionValidator({fun: selCity});
    $("#area1").formValidator({onShow: "", onFocus: "请选择所在地区"})
        .functionValidator({fun: selArea});
    $("#business_license").formValidator({onShow: "", onFocus: "请上传营业执照图片"}).inputValidator({
        min: 1,
        onError: "营业执照不能为空"
    });
    $("#contract").formValidator({onShow: "", onFocus: "请上传合同照片"}).inputValidator({
        min: 1,
        onError: "合同照片不能为空"
    });
    $("#certid_front").formValidator({onShow: "", onFocus: "请上传身份证正面图片"}).inputValidator({
        min: 1,
        onError: "身份证正面图片不能为空"
    });
    $("#certid_side").formValidator({onShow: "", onFocus: "请上传身份证反面图片"}).inputValidator({
        min: 1,
        onError: "身份证反面图片不能为空"
    });
    $("#address").formValidator({onShow: "", onFocus: "请填写详细地址"}).inputValidator({
        min: 1,
        onError: "详细地址不能为空"
    });

    /**
     * 简单校验身份证
     * @param val
     * @param elem
     * @returns {string}
     */
    function isCardID(val, elem) {
        var regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if (!regIdNo.test(val)) {
            return '身份证有误';
        }
    }

    /**
     * 手机号验证
     * @param val
     * @param elem
     * @returns {boolean}
     */
    function isMobile(val, elem) {
        if (!(/^1(3|4|5|7|8)\d{9}$/.test(val))) {
            return '手机号有误';
        }
    }

    /**
     * 固定电话验证
     * @param val
     * @param elem
     * @returns {boolean}
     */
    function isTel(val, elem) {
        if (!/^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(val)) {
            return '固定电话有误，请重填';
        }
    }

    function selProvice(val, elem) {
        if (val == 0)
            return '请选择所在省份';
    }

    function selCity(val, elem) {
        if (val == 0)
            return '请选择所在城市';
    }

    function selArea(val, elem) {
        if (val == 0)
            return '请选择所在地区';
    }
});